package com.wei.czz.common.enums.blog;

import com.wei.czz.common.dto.common.NameValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2024-11-29 14:44:27
 * className: BlogStatusEnum
 * version: 1.0
 * description:
 */
@Getter
@AllArgsConstructor
public enum BlogStatusEnum {

    DRAFT(0, "草稿"),

    AUDIT(10, "审核中"),
    AUDIT_REJECT(11, "审核拒绝"),

    EDIT_AUDIT(50, "编辑审核中"),
    EDIT_AUDIT_REJECT(51, "编辑审核拒绝"),

    APPEAL_AUDIT(70, "申诉审核中"),
    APPEAL_AUDIT_REJECT(71, "申诉审核拒绝"),

    AUDIT_PASS(100, "审核通过"),
    ISSUE(101, "发布"),

    // 不是主状态
    RECOMMEND(110, "推荐"),
    // 不是主状态
    HOT(120, "热门"),

    OFF_LINE(200, "下架"),

    HIDE(210, "隐藏"),

    ;

    /**
     * 值
     */
    private final Integer value;

    /**
     * 名称
     */
    private final String name;

    /**
     * 获取枚举名称
     * @param value 枚举值
     * @return 名称
     */
    public static String getName(Integer value) {
        for (BlogStatusEnum blogStatusEnum : values()) {
            if (blogStatusEnum.value.equals(value)) {
                return blogStatusEnum.name;
            }
        }
        return "";
    }

    /**
     * 获取枚举列表
     * @return 枚举列表
     */
    public static List<NameValue<Integer>> getList() {
        return Stream.of(values())
                .map(blogStatusEnum -> new NameValue<>(blogStatusEnum.getName(), blogStatusEnum.getValue()))
                .collect(Collectors.toList());
    }

    /**
     * 获取枚举对象
     * @param name 名称
     * @return 枚举对象
     */
    public static BlogStatusEnum find(String name) {
        for (BlogStatusEnum blogStatusEnum : values()) {
            if (blogStatusEnum.name.equals(name)) {
                return blogStatusEnum;
            }
        }
        return null;
    }

    /**
     * 获取可编辑的状态枚举列表
     * @return 可编辑的状态枚举列表
     */
    public static List<Integer> getCanEditList() {
        List<Integer> list = new ArrayList<>();
        list.add(DRAFT.getValue());
        list.add(AUDIT_REJECT.getValue());
        list.add(EDIT_AUDIT_REJECT.getValue());
        list.add(AUDIT_PASS.getValue());
        list.add(ISSUE.getValue());
        list.add(HIDE.getValue());
        return list;
    }

    /**
     * 获取审核状态枚举列表
     * @return 审核状态枚举列表
     */
    public static List<Integer> getAuditStatusList() {
        List<Integer> list = new ArrayList<>();
        list.add(AUDIT.getValue());
        list.add(EDIT_AUDIT.getValue());
        list.add(APPEAL_AUDIT.getValue());

        return list;
    }
}
